#include "LogFun.h"
#include "DumpLog.h"
LogFun::LogFun(const std::string &cppFile, const std::string &funName, int lineNo, const std::string &tip):cppFile_(cppFile), funName_(funName), lineNo_(lineNo), tip_(tip)
{
    auto ptr = std::make_shared<Log::LogLine_t>();
    ptr->cppFile = cppFile_;
    ptr->lineNO  = lineNo_;
    ptr->type    = Log::LogType_E::Info_E;
    ptr->info    = "[开始 " + funName_ + "]";
    ptr->time    = std::chrono::_V2::system_clock::now();
    time_        = ptr->time;
    Log::DumpLog::getGlobalLog().pushLog(ptr);
}

LogFun::~LogFun()
{
    auto ptr = std::make_shared<Log::LogLine_t>();
    ptr->cppFile = cppFile_;
    ptr->lineNO  = lineNo_;
    ptr->type    = Log::LogType_E::Info_E;
    ptr->info    = "[结束 " + funName_ + "]";
    ptr->time    = std::chrono::_V2::system_clock::now();
    double t = std::chrono::duration_cast<std::chrono::milliseconds>(ptr->time - time_).count() / 1000.0;
    if (tip_.empty())
    {
        ptr->info += "耗时 "  + std::to_string(t) + "ms";
    }
    else
    {
        ptr->info += tip_ + std::to_string(t) + "ms";
    }

    Log::DumpLog::getGlobalLog().pushLog(ptr);
}
